
const playerStore = {
  namespaced: true,
  state: {
    currentSongIndex: 0, // 当前播放歌曲的索引
    currentSong: {}, // 当前播放的歌曲信息
    sequence: 0, // 0 顺序播放 1 随机 2 单曲循环
    lyricList: [], // 转化 后的 歌词数组
    bgUrl: '',// 背景地址
    currentLyricIndex: 0,// 某一行歌词的索引
    songUrl: '',// 歌曲的 音频地址
    songsList: [
      {
        "name": "有何不可",
        "id": 167876,
        "pst": 0,
        "t": 0,
        "ar": [
          {
            "id": 5771,
            "name": "许嵩",
            "tns": [],
            "alias": []
          }
        ],
        "alia": [],
        "pop": 100,
        "st": 0,
        "rt": "600902000007916021",
        "fee": 8,
        "v": 49,
        "crbt": null,
        "cf": "",
        "al": {
          "id": 16953,
          "name": "自定义",
          "picUrl": "https://p1.music.126.net/Md3RLH0fe2a_3dMDnfqoQg==/18590542604286213.jpg",
          "tns": [],
          "pic_str": "18590542604286213",
          "pic": 18590542604286212
        },
        "dt": 241840,
        "h": {
          "br": 320000,
          "fid": 0,
          "size": 9675799,
          "vd": -21099
        },
        "m": {
          "br": 192000,
          "fid": 0,
          "size": 5805497,
          "vd": -18400
        },
        "l": {
          "br": 128000,
          "fid": 0,
          "size": 3870346,
          "vd": -16900
        },
        "a": null,
        "cd": "1",
        "no": 3,
        "rtUrl": null,
        "ftype": 0,
        "rtUrls": [],
        "djId": 0,
        "copyright": 2,
        "s_id": 0,
        "mark": 8192,
        "originCoverType": 0,
        "single": 0,
        "noCopyrightRcmd": null,
        "mv": 0,
        "mst": 9,
        "cp": 14026,
        "rtype": 0,
        "rurl": null,
        "publishTime": 1231516800000,
        "playing": false
      },
      {
        "name": "雅俗共赏",
        "id": 411214279,
        "pst": 0,
        "t": 0,
        "ar": [
          {
            "id": 5771,
            "name": "许嵩",
            "tns": [],
            "alias": []
          }
        ],
        "alia": [],
        "pop": 100,
        "st": 0,
        "rt": null,
        "fee": 8,
        "v": 31,
        "crbt": null,
        "cf": "",
        "al": {
          "id": 34749138,
          "name": "青年晚报",
          "picUrl": "https://p1.music.126.net/Wcs2dbukFx3TUWkRuxVCpw==/3431575794705764.jpg",
          "tns": [],
          "pic": 3431575794705764
        },
        "dt": 249621,
        "h": {
          "br": 320000,
          "fid": 0,
          "size": 9987177,
          "vd": -22200
        },
        "m": {
          "br": 192000,
          "fid": 0,
          "size": 5992323,
          "vd": -19600
        },
        "l": {
          "br": 128000,
          "fid": 0,
          "size": 3994896,
          "vd": -17800
        },
        "a": null,
        "cd": "1",
        "no": 2,
        "rtUrl": null,
        "ftype": 0,
        "rtUrls": [],
        "djId": 0,
        "copyright": 0,
        "s_id": 0,
        "mark": 8192,
        "originCoverType": 0,
        "single": 0,
        "noCopyrightRcmd": null,
        "mv": 5302271,
        "rtype": 0,
        "rurl": null,
        "mst": 9,
        "cp": 14026,
        "publishTime": 1461723397683,
        "playing": false
      },
      {
        "name": "须尽欢",
        "id": 1465053754,
        "pst": 0,
        "t": 0,
        "ar": [
          {
            "id": 189955,
            "name": "蔡翊昇",
            "tns": [],
            "alias": []
          }
        ],
        "alia": [],
        "pop": 95,
        "st": 0,
        "rt": "",
        "fee": 8,
        "v": 3,
        "crbt": null,
        "cf": "",
        "al": {
          "id": 92888006,
          "name": "须尽欢",
          "picUrl": "https://p2.music.126.net/6hbspsO3-NVIFOIA37ijjw==/109951165162665196.jpg",
          "tns": [],
          "pic_str": "109951165162665196",
          "pic": 109951165162665200
        },
        "dt": 195000,
        "h": {
          "br": 320002,
          "fid": 0,
          "size": 7802925,
          "vd": -47478
        },
        "m": {
          "br": 192002,
          "fid": 0,
          "size": 4681773,
          "vd": -44949
        },
        "l": {
          "br": 128002,
          "fid": 0,
          "size": 3121197,
          "vd": -43399
        },
        "a": null,
        "cd": "01",
        "no": 1,
        "rtUrl": null,
        "ftype": 0,
        "rtUrls": [],
        "djId": 0,
        "copyright": 0,
        "s_id": 0,
        "mark": 8192,
        "originCoverType": 1,
        "originSongSimpleData": null,
        "tagPicList": null,
        "resourceState": true,
        "version": 3,
        "songJumpInfo": null,
        "single": 0,
        "noCopyrightRcmd": null,
        "rtype": 0,
        "rurl": null,
        "mst": 9,
        "cp": 1416917,
        "mv": 0,
        "publishTime": 0
      },

      {
        "name": "删了吧",
        "id": 1891469546,
        "pst": 0,
        "t": 0,
        "ar": [
          {
            "id": 49937403,
            "name": "烟(许佳豪)",
            "tns": [],
            "alias": []
          }
        ],
        "alia": [
          "要不你还是把我删了吧"
        ],
        "pop": 100,
        "st": 0,
        "rt": "",
        "fee": 8,
        "v": 5,
        "crbt": null,
        "cf": "",
        "al": {
          "id": 135521932,
          "name": "删了吧",
          "picUrl": "https://p2.music.126.net/nNg4YjkcK1AwCX1FrN8VOQ==/109951166578333625.jpg",
          "tns": [],
          "pic_str": "109951166578333625",
          "pic": 109951166578333630
        },
        "dt": 204955,
        "h": {
          "br": 320000,
          "fid": 0,
          "size": 8200403,
          "vd": -26816
        },
        "m": {
          "br": 192000,
          "fid": 0,
          "size": 4920259,
          "vd": -24206
        },
        "l": {
          "br": 128000,
          "fid": 0,
          "size": 3280187,
          "vd": -22486
        },
        "a": null,
        "cd": "01",
        "no": 1,
        "rtUrl": null,
        "ftype": 0,
        "rtUrls": [],
        "djId": 0,
        "copyright": 0,
        "s_id": 0,
        "mark": 8192,
        "originCoverType": 0,
        "originSongSimpleData": null,
        "tagPicList": null,
        "resourceState": true,
        "version": 5,
        "songJumpInfo": null,
        "single": 0,
        "noCopyrightRcmd": null,
        "rtype": 0,
        "rurl": null,
        "mst": 9,
        "cp": 0,
        "mv": 0,
        "publishTime": 1636128000000
      },
      {
        "name": "你的姑娘",
        "id": 1356499052,
        "pst": 0,
        "t": 0,
        "ar": [
          {
            "id": 12429072,
            "name": "隔壁老樊",
            "tns": [],
            "alias": []
          }
        ],
        "alia": [],
        "pop": 100,
        "st": 0,
        "rt": "",
        "fee": 8,
        "v": 80,
        "crbt": null,
        "cf": "",
        "al": {
          "id": 75019098,
          "name": "我曾",
          "picUrl": "https://p2.music.126.net/gNbAlXamNjhR2j3aOukNhg==/109951164232796511.jpg",
          "tns": [],
          "pic_str": "109951164232796511",
          "pic": 109951164232796510
        },
        "dt": 248124,
        "h": {
          "br": 320000,
          "fid": 0,
          "size": 9927619,
          "vd": -17600
        },
        "m": {
          "br": 192000,
          "fid": 0,
          "size": 5956589,
          "vd": -14900
        },
        "l": {
          "br": 128000,
          "fid": 0,
          "size": 3971074,
          "vd": -13300
        },
        "a": null,
        "cd": "01",
        "no": 5,
        "rtUrl": null,
        "ftype": 0,
        "rtUrls": [],
        "djId": 0,
        "copyright": 0,
        "s_id": 0,
        "mark": 0,
        "originCoverType": 1,
        "originSongSimpleData": null,
        "tagPicList": null,
        "resourceState": true,
        "version": 80,
        "songJumpInfo": null,
        "single": 0,
        "noCopyrightRcmd": null,
        "mv": 10864930,
        "mst": 9,
        "cp": 0,
        "rtype": 0,
        "rurl": null,
        "publishTime": 0
      }
    ],// 存储的  歌曲播放列表
    isPlaying: false,// flase 是暂停，true 是播放
    lyricY: 0,// 歌词向上滚动的 Y 轴距离
  },
  mutations: {
    // 切换 播放 的状态  是 顺序 还是随机  还是单曲
    toggleSequence(state) {
      if (state.sequence == 2) {
        state.sequence = 0
      } else {
        console.log('否则');
        state.sequence = state.sequence + 1
      }
    },
    // 添加 歌曲
    changeSongsListMutations(state, item) {
      let flag = state.songsList.some(i => {
        return i.id == item.id
      })
      if (flag) {
        return
      }
      //  列表中没有这个歌曲的时候
      state.songsList = [...state.songsList, item]

    },
    // 当前 激活的 歌曲 信息
    changeCurrentSongMutations(state, item) {
      state.currentSong = item
      state.bgUrl = item.al.picUrl
      let index = state.songsList.findIndex(i => {
        return i.id == item.id
      })
      state.currentSongIndex = index
    },
    // 当前歌曲的 url
    changeSongUrlMutations(state, url) {
      state.songUrl = url
    },
    changeLyricListMutations(state, lyric) {
      state.lyricList = lyric
    },
    changeIsPlaying(state, flag) {
      state.isPlaying = flag
    },
    changeCurrentLyricIndexMutations(state, index) {
      state.currentLyricIndex = index
    },
    changeLyricYMutations(state, y) {
      state.lyricY = y
    },
  },
  actions: {}
}



export default playerStore